<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
	<!DOCTYPE html>
        <html lang="zh-cn">

        <head>
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>订单详情</title>
            <link rel="stylesheet" type="text/css" href="${ctxStatic}/IDH/css/myAccount.css" />
		    <link rel="stylesheet" type="text/css" href="${ctxStatic}/jq-address/css/select2.css" />
		    <link rel="stylesheet" type="text/css" href="${ctxStatic}/IDH/css/marketOrder/order.css" />
		    <link rel="stylesheet" type="text/css" href="${ctxStatic}/jq-address/css/common.css" />
    	
        </head>

        <body>
            <!-- header -->
            <%@ include file="/WEB-INF/views/modules/marketHeader.jsp"%>
                <!-- 主题内容 -->
                <section class="container content">
                    <div class="col-xs-12 col-md-12 allform">
                        <div class="allOrder col-xs-12">
                        	<form:form id="orderFrm" modelAttribute="shopOrder" action="${ctxf}/front/cart/genCart/order" method="post" class="form-horizontal">
                        		<input type="hidden" id="cartid" name="cartid" value="${id }"/>
                        		<!-- shop_order -->
                        		<!-- 备注信息 -->
                        		<form:hidden path="comment" id="comment" />
                        		<!-- 商品总金额 -->
                        		<form:hidden path="totalAmountProduct" id="totalAmountProduct" />
                        		<!-- 配送费 -->
                        		<form:hidden path="freight" id="freight" />
                        		<!-- 订单总金额 -->
                        		<form:hidden path="totalAmount" id="totalAmount" />
                        		
                        		<!-- shop_order_receiving -->
                        		<!-- 快递公司 -->
                        		<form:hidden path="shopOrderReceiving.company" id="company" />
                        		<!-- 收货地址 -->
				        		<form:hidden path="shopOrderReceiving.address" id="address"  value="${defaultAddress.province }${defaultAddress.city }${defaultAddress.countyTown }${defaultAddress.detail }"/>
				        		<!--收货人 -->
				        		<form:hidden path="shopOrderReceiving.name" id="receivername"  value="${defaultAddress.addUsername }"/>
				        		<!--电话号码  -->
				        		<form:hidden path="shopOrderReceiving.telephone" id="telephone2"  value="${defaultAddress.addTelnum }"/>
				        		
				        		<!-- 发票信息 -->
				        		<!-- 发票台头 -->
				        		<form:hidden path="shopOrderReceipt.head" id="invoiceHead" />
				        		<!-- 单位名称 -->
				        		<form:hidden path="shopOrderReceipt.name" id="unitName" />
				        		<!-- 纳税人识别码 -->
				        		<form:hidden path="shopOrderReceipt.code" id="taxpayerIdentificationCode" />
				        		<!-- 注册地址 -->
				        		<form:hidden path="shopOrderReceipt.address" id="registerAddress" />
				        		<!-- 开户银行 -->
				        		<form:hidden path="shopOrderReceipt.bankName" id="bank" />
				        		<!-- 银行账户 -->
				        		<form:hidden path="shopOrderReceipt.bankAccount" id="bankAccount" />
				        		<!-- 发票类型 -->
				        		<form:hidden path="shopOrderReceipt.type" id="type" value="1"/>
				        	</form:form>
                            <div class="title">填写并核对订单信息</div>
                            <div class="address-part col-xs-12">
                                <div><label>选择收货地址</label><span class="new-address-btn" onclick="addNewAddress()">新建地址</span>
								<span class="p_new_address_model">新建地址</span></div>
                                <div class="allAddress">
                                <div class="col-xs-12 address">
	                                <span class="address-text" id="defaultUserName">${defaultAddress.addUsername }</span>
	                                <span class="address-text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
	                                <span class="address-text" id="defaultTele">${defaultAddress.addTelnum }</span>
	                                <br />
	                                <span class="address-text" id="defaultAddress">${defaultAddress.province }${defaultAddress.city }${defaultAddress.countyTown }   ${defaultAddress.detail }</span>
	                                <div class="col-xs-12 addresList">
	                                	<c:forEach items="${commonAddresses }" var="address">
	                                		<div class="col-xs-12 address">
	                                			<input type="radio" name="choose" class="choose-radio" onclick="chooseAddress('${address.id }')">
	                                			<span class="address-text" id="commonUsername${address.id }">${address.addUsername }</span>
	                                			<span class="address-text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
	                                			<span class="address-text" id="commonTele${address.id }">${address.addTelnum }</span>
	                                			<br />
	                                			<span class="address-text mr" id="commonAddress${address.id }">${address.province }${address.city }${address.countyTown }   ${address.detail }</span>
	                               			</div>
	                                	</c:forEach>
	                                	<input type="hidden" name="maxAddressLenght" id="maxAddressLenght" value="${commonAddresses.size()}" />
	                                </div>
                                </div>
                                <div class="col-xs-12 more-address ${empty  commonAddresses ? 'hide': ''}" id="moreAddressBtn">更多收货地址</div>
                                </div>
                            </div>
                            <div class="mail-part col-xs-12">
                                <div>
                                    <label>发票信息</label>
                                    <div class="tax-type">
                                        <span id="normailTaxBtn" onclick="showNormailTax()">增值税普通发票</span>&nbsp;&nbsp;|&nbsp;&nbsp;
                                        <span id="specialTaxBtn" onclick="showSpecialTax()">增值税专用发票</span>
                                    </div>
                                </div>
                                <div class="row">
                                	<div class="col-lg-4  col-md-4 col-xs-12 tax-content normailTax">
                                    <input id="taxInfo1" class="form-control" placeholder="发票抬头">
                                    <span class="warnInfo col-xs-12" id="taxWarn1"><i class="glyphicon glyphicon-minus-sign"></i>发票抬头不能为空！</span>
                                </div>
                                </div>
                                <div class="row">
                                	<div class="col-lg-4  col-md-4 col-xs-12 tax-content specialTax">
	                                    <input id="taxInfo2" class="form-control" placeholder="单位名称">
	                                    <span class="warnInfo" id="taxWarn2"><i class="glyphicon glyphicon-minus-sign"></i>单位名称不能为空！</span>
	                                </div>
                                </div>
                                <div class="row">
                                	<div class="col-lg-4  col-md-4 col-xs-12 tax-content specialTax">
	                                    <input id="taxInfo3" class="form-control" placeholder="纳税人识别码">
	                                    <span class="warnInfo" id="taxWarn3"><i class="glyphicon glyphicon-minus-sign"></i>纳税人识别码不能为空！</span>
	                                </div>
                                </div>
                                <div class="row">
                                	<div class="col-lg-4  col-md-4 col-xs-12 tax-content specialTax">
	                                    <input id="taxInfo4" class="form-control" placeholder="注册地址">
	                                    <span class="warnInfo" id="taxWarn4"><i class="glyphicon glyphicon-minus-sign"></i>注册地址不能为空！</span>
	                                </div>
                                </div>
                                <div class="row">
                                	 <div class="col-lg-4  col-md-4 col-xs-12 tax-content specialTax">
	                                    <input id="taxInfo5" class="form-control" placeholder="开户银行">
	                                    <span class="warnInfo" id="taxWarn5"><i class="glyphicon glyphicon-minus-sign"></i>开户银行不能为空！</span>
	                                </div>
                                </div>
                                <div class="row">
                                	 <div class="col-lg-4  col-md-4 col-xs-12 tax-content specialTax">
	                                    <input id="taxInfo6" class="form-control" placeholder="银行账户">
	                                    <span class="warnInfo" id="taxWarn6"><i class="glyphicon glyphicon-minus-sign"></i>银行账户不能为空！</span>
	                                </div>
                                </div>
                            </div>
                            <div class="mail-part col-xs-12">
                                <div><label>您购买了以下产品</label></div>
                            </div>
                            <c:set var="sum" value="0"></c:set>
                            <c:forEach items="${genCarts }" var="genCart">
                            	<div class="product-list col-xs-12">
	                                <div class="row">
	                                    <div class="col-sm-2 col-xs-4"><img src="${path }${genCart.picture }"></div>
	                                    <div class="col-sm-4 col-xs-4">
	                                        <div class="col-xs-12"><span class="product-title">${genCart.productName }</span></div>
	                                        <div class="col-xs-12 product-num-fa"><span class="product-num">商品编号:${genCart.code }</span></div>
											<div class="col-xs-12 visibleXs"><span>${genCart.code }</span></div>
	                                    </div>
	                                    <div class="col-sm-2 hidden-xs"><span class="product-money">￥${genCart.price2 }</span></div>
	                                    <div class="col-sm-2 hidden-xs"><span class="">x${genCart.amt }</span></div>
	                                    <div class="col-sm-2 hidden-xs">小计&nbsp;&nbsp;&nbsp;&nbsp;
	                                    	<span class="product-money">￥${genCart.price2*genCart.amt }</span>
	                                    </div>
										<div class="visibleXs col-xs-4">
											<span class="product-money col-xs-12">￥${genCart.price2*genCart.amt }</span>
											<span class="col-xs-12" style="text-align: right;">x${genCart.amt }</span>
										</div>
	                                </div>
	                            </div>
	                            <c:set var="sum" value="${sum + genCart.amt * genCart.price2 }"></c:set>
                            </c:forEach>
                            <div class="mail-part col-xs-12">
                                <div class="col-sm-1 col-xs-12"><span>添加备注</span></div>
                                <div class="col-sm-8 col-xs-12"><textarea width="100%" id="comment1"></textarea></div>
                                <div class="col-sm-3 col-xs-12 total">
                                    <div class="col-xs-6 totalin"><span>商品总价</span></div><div class="col-xs-6 totalin"><span class="product-money">￥<label id="totalAmountProductLabel">${sum }</label></span></div>
                                    <div class="col-xs-6 totalin"><span>运费</span></div><div class="col-xs-6 totalin"><span class="product-money">+￥<label id="freightLabel">20.00</label></span></div>
                                    <div class="col-xs-6 totalin"><span>应付款金额</span></div><div class="col-xs-6 totalin"><span class="product-money">￥<label id="totalAmountLabel">${sum + 20}</label></span></div>
                                </div>
                            </div>
                            <div class="col-xs-12">
                                <button class="submit-btn" onclick="order();">提交订单</button>
                            </div>
                        </div>
                        <!--phone add new  address start-->
						<div class="p_add_address row">
							<form class="" id="phone" action="" method="post">
								<div class="form-group">
									<div class="col-xs-12 control-label">
										<label for="title">收货人</label>
									</div>
									<div class="col-xs-12">
										<input type="text" id="suppReceiverName" name="suppReceiverName" class="form-control" placeholder="收货人" autofocus value="">
									</div>
								</div>
								<div class="form-group">
									<div class="col-xs-12 control-label">
										<label for="title">联系电话</label>
									</div>
									<div class="col-xs-12">
										<input type="text" id="suppReceiverTelephone" name="suppReceiverTelephone" class="form-control" placeholder="联系电话" autofocus value="">
									</div>
								</div>
								<div class="form-group">
									<div class="col-xs-12 col-lg-12 control-label">
										<div class="row">
											<div class="col-xs-4">
												<label for="title">请选择省份</label>
											</div>
											<div class="col-xs-8">
												<select name="loc_province2" id="loc_province2" onchange="getPrivePhone()"></select>
												<input style="visibility: hidden;" name="province2" id="province2"/>
											</div>
										</div>
									</div>
								</div>
								<div class="form-group">
									<div class="col-xs-12 col-lg-12 control-label">
										<div class="row">
											<div class="col-xs-4">
												<label for="title">请选择地区</label>
											</div>
											<div class="col-xs-8">
												<select name="loc_city2" id="loc_city2" onchange="getCityPhone()"></select>
												<input style="visibility: hidden;" name="city2"  id="city2"/>
											</div>
										</div>
									</div>
								</div>
								<div class="form-group">
									<div class="col-xs-12 col-lg-12 control-label">
										<div class="row">
											<div class="col-xs-4">
												<label for="title">请选择街道</label>
											</div>
											<div class="col-xs-8">
												<select name="loc_town2" id="loc_town2" onchange="getTownPhone()"></select>
												<input style="visibility: hidden;" name="countyTown2" id="countyTown2"/>
											</div>
										</div>
									</div>
								</div>
								<div class="form-group">
									<div class="col-xs-12 col-lg-12 control-label">
										<div class="row">
											<div class="col-xs-12">
												<label for="title">详细地址</label>
											</div>
											<div class="col-xs-12">
												<input type="text" id="suppDetail" name="suppDetail" class="form-control" placeholder="详细地址" autofocus>
											</div>
										</div>
									</div>
								</div>
								<!-- <div class="row">
									<div class="col-xs-12 col-lg-12 form-group">
										<div class="row">
											<div class="col-xs-12">
												<input type="checkbox" name="" id="phoneSetFomartAddress" value="" onclick="addressCheck()" />
												<a href="#">设为默认地址</a>
											</div>
										</div>
									</div>
								</div> -->
								<div class="row p_add_address_btn">
									<div class="col-xs-12 col-lg-12 form-group">
										<button type="submit" class="btn btn-primary col-xs-5" id="phone-save-address" onclick="addressSave2();">保存</button>
										<button type="button" class="btn btn-default col-xs-5 pull-right" onclick="addressCancel();">取消</button>
									</div>
								</div>
							</form>
						</div>
						<!--phone add new  address end-->
                    </div>
                </section>
                <!-- PC 新增地址模态框 开始-->
				<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<h4 class="modal-title" id="myModalLabel">添加收货地址</h4>
							</div>
							<div class="modal-body">
								<form id="df" class="form-horizontal" action="" method="post">
									<input type="hidden" id="addressAccountId" value="${user.id}" />
									<input type="hidden" name="id" id="addId" value="${id }"/>
									<div class="form-group name-tel">
										<div class="col-md-12">
											<div class="control-label col-md-2">
												<label class="title-labal" for="title ">收货人:</label>
											</div>
											<div class="input-row col-md-4">
												<input type="text" id="receiverName" name="addUsername" class="form-control middelInput" value=""  autofocus>
											</div>
											<div class="control-label col-md-2">
												<label for="title">联系电话:</label>
											</div>
											<div class="input-row col-md-4">
												<input type="text" id="receiverTelePhone" name="addTelnum" class="form-control middelInput" value=""  autofocus>
											</div>
										</div>
									</div>
									<div class="form-group loc-adress">
										<div class="col-md-12">
											<div class="col-md-4">
												<select onchange="getPrive()" id="loc_province"></select>
													<input style="visibility: hidden;"  name="province" id="province"  />
											</div>
											<div class="col-md-4">
												<select onchange="getCity()" id="loc_city"></select>
													<input style="visibility: hidden;"  id="city" name="city" />
											</div>
											<div class="col-md-4">
												<select onchange="getTown()" id="loc_town"></select>
													<input style="visibility: hidden;" id="countyTown" name="countyTown" />
											</div>
										</div>
									</div>
									<div class="form-group address-input">
										<div class="col-md-12">
											<div class="control-label col-md-2">
												<label for="detail">详细地址</label>
											</div>
											<div class="col-md-10">
												<input type="text" id="detail" name="detail" class="form-control" autofocus>
											</div>
										</div>
									</div>
									<!-- <div class="row">
										<div class="col-xs-12 col-lg-12 form-group">
											<div class="row">
												<div class="col-xs-4 col-sm-4 text-center">
													<input type="hidden" name="defAdd" id="ress" value="true" onclick="addressCheck()" />
													<input id="setFormatAddress" type="checkbox" checked="checked" onclick="addressCheck()" />设为默认地址
												</div>
											</div>
										</div>
									</div> -->
									<div class="modal-footer">
										<button type="submit" onclick="addressSave()" id="pc-save-address" class="btn btn-primary">保存</button>
										<button type="button" onclick="pcAddressCancel()" class="btn btn-default">取消</button>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
				<!--模态框 结束-->
		        
		        <!-- footer -->
        		<%@ include file="/WEB-INF/views/modules/marketFooter.jsp"%>
        </body>
        </html>
	    <script src="${ctxStatic}/jq-address/js/select2.js" type="text/javascript" charset="utf-8"></script>
	    <script src="${ctxStatic}/jq-address/js/location.js" type="text/javascript" charset="utf-8"></script>
	    <script src="${ctxStatic}/jq-address/js/area.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
            var taxType = "normal";
            var enableSubmit = false;
			var newAddressList = new Array(); 
			var newAddressId = 0;
			var newAddresses = '';
			
			$(document).ready(function(){
				$('#df').bootstrapValidator({
					 message: 'This value is not valid',
				        feedbackIcons: {
				            valid: '',
				            invalid: '',
				            validating: ''
				        },
				        fields: {
				            'addTelnum': {
				                validators: {
				                	notEmpty: {
				                        message: '请填写联系电话'
				                    },
				                	/*regexp: {
				                        regexp: /^((0\d{2,3}-{0,1}\d{7,8})|(1[3584]\d{9}))$/,
				                        message: '请输入正确的联系电话'
				                    }*/
				                }
				            },
					        'addUsername': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请填写收货人'
				                    }
				                }
				            },
				            'province': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择省份'
				                    }
				                }
				            },
				            'city': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择城市'
				                    },
				                }
				            },
				            'countyTown': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择地区街道'
				                    }
				                }
				            },
				            'detail': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择详细地址'
				                    }
				                }
				            },
				        }
				});
				/* 手机端 */
				$('#phone').bootstrapValidator({
					 message: 'This value is not valid',
				        feedbackIcons: {
				            valid: '',
				            invalid: '',
				            validating: ''
				        },
				        fields: {  
				            'suppReceiverTelephone': {
				                validators: {
				                	notEmpty: {
				                        message: '请填写联系电话'
				                    },
				                	/*regexp: {
				                        regexp: /^((0\d{2,3}-{0,1}\d{7,8})|(1[3584]\d{9}))$/,
				                        message: '请输入正确的联系电话'
				                    }*/
				                }
				            },
					        'suppReceiverName': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请填写收货人'
				                    }
				                }
				            },
				            'province2': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择省份'
				                    }
				                }
				            },
				            'city2': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择城市'
				                    },
				                }
				            },
				            'countyTown2': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择地区街道'
				                    }
				                }
				            },
				            'suppDetail': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择详细地址'
				                    }
				                }
				            },
				        }
				})
			})
			
			
            function addNewAddress(){
                $('#myModal').modal("show");
            }
			function chooseNewAddress(id){
				$("#defaultAddress").html(newAddressList[parseInt(id)]);
	        	$("#address").val(newAddressList[parseInt(id)]);
				$("#moreAddressBtn").css("display","block");
	            $(".addresList").css("display","none");
			}
            /* 移动端点击     取消添加地址  */
		    function addressCancel(){
			    $('.allOrder').css({"display":"block"});
			    $(".p_add_address").css({"display":"none"});
			    formClear("phone");
		    }
		    /* pc端点击     取消添加地址  */
		    function pcAddressCancel(){
		    	$('#myModal').modal('hide');
			    formClear("df");
		    }
	        function order() {
	            if(taxType=="normal"){
	                if($("#taxInfo1").val() == ''){
						$("#taxWarn1").css("display","none");
						enableSubmit = true;
	                }else {$("#taxWarn1").css("display","none");
	                enableSubmit = true;}
	            }
	            else if(taxType=="special"){
	                enableSubmit = true;
	                for(var i=2;i<7;i++){
	                    if($("#taxInfo"+i+"").val() == ''){
	                        $("#taxWarn"+i+"").css("display","inline-block");
	                        enableSubmit = false;
	                    }else $("#taxWarn"+i+"").css("display","none");
	                }
	            };
                if(enableSubmit == true){
                    submitForm();
                }
	        }
            function submitForm(){
                $("#freight").val($("#freightLabel").html());
       			$("#totalAmount").val($("#totalAmountLabel").html());
	        	$("#totalAmountProduct").val($("#totalAmountProductLabel").html());
	        	$("#comment").val($("#comment1").val());
	        	$("#invoiceHead").val($("#taxInfo1").val());
	        	$("#unitName").val($("#taxInfo2").val());
	        	$("#taxpayerIdentificationCode").val($("#taxInfo3").val());
	        	$("#registerAddress").val($("#taxInfo4").val());
	        	$("#bank").val($("#taxInfo5").val());
	        	$("#bankAccount").val($("#taxInfo6").val());
	        	
	        	if ($("#defaultUserName").html() == "") {
	        		layer.open({title: '提示',content: '请选择收货地址!',icon: 0});
	        		return false;
	        	}
	        	$("#orderFrm").submit();
	        }
	        function chooseAddress(id){
    			$("#defaultUserName").html($("#commonUsername" + id).html());
    			$("#defaultTele").html($("#commonTele" + id).html());
	        	$("#defaultAddress").html($("#commonAddress" + id).html());
	        	
	        	$("#address").val($("#defaultAddress").html());
	        	$("#receivername").val($("#defaultUserName").html());
	        	$("#telephone2").val($("#defaultTele").html());
	        	
	            $("#moreAddressBtn").css("display","block");
	            $(".addresList").css("display","none");
	        }
            function showNormailTax(){
            	$("#type").val("1");
                taxType = "normal";
                $(".normailTax").css("display","block");
                $("#normailTaxBtn").css("color","#2499b1");
                $(".specialTax").css("display","none");
                $("#specialTaxBtn").css("color","black");
            }
            function showSpecialTax(){
            	$("#type").val("2");
                taxType = "special";
                $(".normailTax").css("display","none");
                $("#normailTaxBtn").css("color","black");
                $(".specialTax").css("display","block");
                $("#specialTaxBtn").css("color","#2499b1");
            }
            
            
    		/* pc 添加地址 change 事件 开始 */
			function getPrive(){
				if($('#select2-chosen-1').html() != "省份"){
					$('#province').val($('#select2-chosen-1').html());
					$('#df').data('bootstrapValidator').updateStatus('province','NOT_VALIDATED',null).validateField('province');
				}else{
					$('#province').val("");
					$('#df').data('bootstrapValidator').updateStatus('province','NOT_VALIDATED',null).validateField('province');
				}
			}
			function getCity(){
				if($('#select2-chosen-2').html() != "地级市"){
					$('#city').val($('#select2-chosen-2').html());
					$('#df').data('bootstrapValidator').updateStatus('city','NOT_VALIDATED',null).validateField('city');
				}else{
					$('#city').val("");
					$('#df').data('bootstrapValidator').updateStatus('city','NOT_VALIDATED',null).validateField('city');
				}
			}
			function getTown(){
				if($('#select2-chosen-3').html() != "市、县、区"){
					$('#countyTown').val($('#select2-chosen-3').html());
					$('#df').data('bootstrapValidator').updateStatus('countyTown','NOT_VALIDATED',null).validateField('countyTown');
				}else{
					$('#countyTown').val("");
					$('#df').data('bootstrapValidator').updateStatus('countyTown','NOT_VALIDATED',null).validateField('countyTown');
				}
			}
			/* pc 添加地址 change 事件结束*/
    		
    		
    		/* 移动端添加地址 change 事件 开始 */
			function getPrivePhone(){
				if($('#select2-chosen-4').html() != "省份"){
					$('#province2').val($('#select2-chosen-4').html());
					$('#phone').data('bootstrapValidator').updateStatus('province2','NOT_VALIDATED',null).validateField('province2');
				}else{
					$('#province2').val("");
					$('#phone').data('bootstrapValidator').updateStatus('province2','NOT_VALIDATED',null).validateField('province2');
				}
			}
			function getCityPhone(){
				if($('#select2-chosen-5').html() != "地级市"){
					$('#city2').val($('#select2-chosen-5').html());
					$('#phone').data('bootstrapValidator').updateStatus('city2','NOT_VALIDATED',null).validateField('city2');
				}else{
					$('#city2').val("");
					$('#phone').data('bootstrapValidator').updateStatus('city2','NOT_VALIDATED',null).validateField('city2');
				}
			}
			function getTownPhone(){
				if($('#select2-chosen-6').html() != "市、县、区"){
					$('#countyTown2').val($('#select2-chosen-6').html());
					$('#phone').data('bootstrapValidator').updateStatus('countyTown2','NOT_VALIDATED',null).validateField('countyTown2');
				}else{
					$('#countyTown2').val("");
					$('#phone').data('bootstrapValidator').updateStatus('countyTown2','NOT_VALIDATED',null).validateField('countyTown2');
				}
			}
			/* 移动端添加地址 change 事件 结束 */
    		
    		//pc端提交按钮
			$("#pc-save-address").on("click", function(){
				if($("#maxAddressLenght").val() >= 10){
					$('#myModal').modal("hide");
					layer.open({title: '提示', content: '最多只能添加10个地址，请删除旧地址重新添加', icon: 0});
					return false;
				}
			});
			//phone端提交按钮
			$("#phone-save-address").on("click", function(){
				if($("#maxAddressLenght").val() >= 10){
					$('#myModal').modal("hide");
					layer.open({title: '提示', content: '最多只能添加10个地址，请删除旧地址重新添加', icon: 0});
					return false;
				}
			});
    		
            function addressSave() {
            	$('#df').bootstrapValidator({
					 message: 'This value is not valid',
				        feedbackIcons: {
				            valid: '',
				            invalid: '',
				            validating: ''
				        },
				        fields: {
				            'addTelnum': {
				                validators: {
				                	notEmpty: {
				                        message: '请填写联系电话'
				                    },
				                	regexp: {
				                        regexp: /^((0\d{2,3}-{0,1}\d{7,8})|(1[3584]\d{9}))$/,
				                        message: '请输入正确的联系电话'
				                    }
				                }
				            },
					        'addUsername': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请填写收货人'
				                    }
				                }
				            },
				            'province': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择省份'
				                    }
				                }
				            },
				            'city': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择城市'
				                    },
				                }
				            },
				            'countyTown': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择地区街道'
				                    }
				                }
				            },
				            'suppDetail': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择详细地址'
				                    }
				                }
				            },
				        }
				}).on('success.form.bv', function (e) {
					e.preventDefault();
					console.log('Coucou'); 
					newAddresses = $('#receiverName').val()+'   '+$('#receiverTelePhone').val()+'   '+$('#province').val()+$('#city').val()+$('#countyTown').val()+'   '+$("#detail").val();
	            	$.ajax({
	    				type:"POST",
	    				data:{
	    					receiverName:$("#receiverName").val(),
	    					receiverTelePhone:$("#receiverTelePhone").val(),
	    					province:$('#province').val(),
	    					city:$('#city').val(),
	    					countyTown:$('#countyTown').val(),
	    					detail:$("#detail").val(),
	    					accountId:$("#addressAccountId").val()
	    				},
	    				async: false,
	    				url: "${ctxf}/front/cart/genCart/saveAddress",
	    				dataType:"json",
	    				success:function(data){
	    					layer.open({title: '提示',content: '新地址添加成功!',icon: 1});
	    					
	    					$("#defaultUserName").html($('#receiverName').val()+'   ');
	    	    			$("#defaultTele").html($('#receiverTelePhone').val()+'   ');
	    		        	$("#defaultAddress").html($('#province').val()+$('#city').val()+$('#countyTown').val()+'   '+$("#detail").val());
	    		        	
	    		        	$("#address").val($("#defaultAddress").html());
	    		        	$("#receivername").val($("#defaultUserName").html());
	    		        	$("#telephone2").val($("#defaultTele").html());
	    		        	
							newAddressList[newAddressId] = newAddresses;
							$(".addresList").append('<div class="col-xs-12 address"><input type="radio" name="choose" class="choose-radio" onclick="chooseNewAddress('+newAddressId+')"><span class="address-text">'+newAddresses+'</span></div>');
							newAddressId++;
							$('#myModal').modal('hide');
							
							/* 清空表单 */
							formClear("df");
							
						},
	    				error:function() {
	    				}
	    			});	
				});
            }
           
            function addressSave2() {
            	$('#phone').bootstrapValidator({
					 message: 'This value is not valid',
				        feedbackIcons: {
				            valid: '',
				            invalid: '',
				            validating: ''
				        },
				        fields: {  
				            'suppReceiverTelephone': {
				                validators: {
				                	notEmpty: {
				                        message: '请填写联系电话'
				                    },
				                	regexp: {
				                        regexp: /^((0\d{2,3}-{0,1}\d{7,8})|(1[3584]\d{9}))$/,
				                        message: '请输入正确的联系电话'
				                    }
				                }
				            },
					        'suppReceiverName': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请填写收货人'
				                    }
				                }
				            },
				            'province2': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择省份'
				                    }
				                }
				            },
				            'city2': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择城市'
				                    },
				                }
				            },
				            'countyTown2': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择地区街道'
				                    }
				                }
				            },
				            'suppDetail': {
				                message: '',
				                validators: {
				                    notEmpty: {
				                        message: '请选择详细地址'
				                    }
				                }
				            },
				        }
				}).on('success.form.bv', function (e) {
					e.preventDefault();
					newAddresses = $('#suppReceiverName').val()+'   '+$('#suppReceiverTelephone').val()+'   '+ $('#province2').val()+$('#city2').val()+$('#countyTown2').val()+'   '+$("#suppDetail").val();
	            	$.ajax({
	    				type:"POST",
	    				data:{
	    					receiverName:$("#suppReceiverName").val(),
	    					receiverTelePhone:$("#suppReceiverTelephone").val(),
	    					province:$('#province2').val(),
	    					city:$('#city2').val(),
	    					countyTown:$('#countyTown2').val(),
	    					detail:$("#suppDetail").val(),
	    					accountId:$("#addressAccountId").val()
	    				},
	    				async: false,
	    				url: "${ctxf}/front/cart/genCart/saveAddress",
	    				dataType:"json",
	    				success:function(data){
	    					layer.open({title: '提示',content: '新地址添加成功!',icon: 1});
	    					
	    					$("#defaultUserName").html($("#suppReceiverName").val()+'   ');
	    	    			$("#defaultTele").html($('#suppReceiverTelephone').val()+'   ');
	    		        	$("#defaultAddress").html($('#province2').val()+$('#city2').val()+$('#countyTown2').val()+'   '+$("#suppDetail").val());
	    		        	
	    		        	$("#address").val($("#defaultAddress").html());
	    		        	$("#receivername").val($("#defaultUserName").html());
	    		        	$("#telephone2").val($("#defaultTele").html());
	    		        	
							newAddressList[newAddressId] = newAddresses;
							$(".addresList").append('<div class="col-xs-12 address"><input type="radio" name="choose" class="choose-radio" onclick="chooseNewAddress('+newAddressId+')"><span class="address-text">'+newAddresses+'</span></div>');
							newAddressId++;
							addressCancel();
							formClear("phone")
	    				},
	    				error:function() {
	    				}
	    			});
				});
            }
            
    		function addressCheck(){
    			$("#ress").val("false");
    		}
            
	        $(function(){
	            $("#moreAddressBtn").click(function(){
	                $(".addresList").css("display","block");
	                $("#moreAddressBtn").css("display","none");
	            });
                /* 移动端点击     添加地址  */
			    $('.p_new_address_model').click(function() {
				    $('.allOrder').css({"display":"none"});
				    $(".p_add_address").css({"display":"block"});
			    });
	        });
	        
	        /* 清空表单 */
	        function formClear(id){
	        	$('#'+ id)[0].reset();
	        	$('#select2-chosen-1').html("");
	    		$('#select2-chosen-2').html("");
	    		$('#select2-chosen-3').html("");
	    		$('#select2-chosen-4').html("");
    			$('#select2-chosen-5').html("");
    			$('#select2-chosen-6').html("");
	        }
        </script>